package cn.changein.framework.api.base;

import cn.changein.framework.base.controller.BaseController;
import cn.changein.framework.kernel.model.response.ResponseData;
import cn.changein.framework.modular.fileInfo.model.FileUploadParam;
import cn.changein.framework.modular.fileInfo.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p> TODO(file handler) </p>
 *

 * @version V1.0
 * @Title: ApiFileController
 * @Package cn.changein.framework.api.base
 * @date 2021/1/28 15:47
 * @Copyright: companyName
 */
@RestController
@RequestMapping("/api/file")
public class ApiFileController extends BaseController {

    @Autowired
    private FileService fileService;

    /**
     * @Description: 上传文件
     * @Date:2021/1/28 16:37
     * @Param: [fileUploadParam, servletRequest, httpServletResponse]

     */
    @PostMapping(value = "/uploadFile")
    public ResponseData uploadPicture(FileUploadParam fileUploadParam, HttpServletRequest servletRequest, HttpServletResponse httpServletResponse) {
        MultipartFile file = fileUploadParam.getFile();
        String moduleCode = fileUploadParam.getModuleCode();
        String moduleName = fileUploadParam.getModuleName();
        return fileService.uploadFile(file, moduleCode, moduleName, servletRequest, httpServletResponse);
    }
}
